package com.sfj.system.service.task;

import com.sfj.system.dto.task.ProblemCheckDTO;
import com.sfj.system.entity.ProblemProcessEntity;
import com.sfj.system.mapper.ProblemProcessMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

/**
 * @author kaka
 * @Date 2025/07/07
 */
@Service
public class ProblemProcessService {

    @Resource
    private ProblemProcessMapper problemProcessMapper;
    @Transactional
    public int createProblemProcess(ProblemProcessEntity problemProcess) {
        return problemProcessMapper.insert(problemProcess);
    }

    @Transactional
    public int updateProblemProcess(ProblemProcessEntity problemProcess) {
        return problemProcessMapper.update(problemProcess);
    }

    @Transactional
    public int updStatus(ProblemProcessEntity problemProcess) {
        return problemProcessMapper.updStatus(problemProcess);
    }

    public ProblemProcessEntity getProblemProcessById(Integer problemId,Integer taskId,Integer userId) {
        return problemProcessMapper.selectById(problemId,taskId,userId);
    }

    public List<ProblemCheckDTO> getProblemProcessesByTaskId(Integer taskId) {
        return problemProcessMapper.selectByTaskId(taskId);
    }

    public int countByNotReviewed(Integer taskId){
        return problemProcessMapper.countByNotReviewed(taskId);
    }
    public int countByNotReviewed(Integer taskId,Integer userId){
        return problemProcessMapper.countByNotReviewedByUserId(taskId,userId);
    }

    public void updateRectifyDate(Integer taskId,Integer userId){
        LocalDateTime now = LocalDateTime.now().withNano(0); // 去掉毫秒部分
        problemProcessMapper.updateRectifyDate(taskId,userId,now);
    }

    @Transactional
    public int deleteProblemProcess(Integer problemId) {
        return problemProcessMapper.delete(problemId);
    }
}
